package yf.mall.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;

import java.util.Map;

import com.yf.consts.DaoConst;
import yf.mall.entity.SaleTypesEntity;
import com.yf.response.R;
import yf.mall.service.SaleTypesService;


/**
 * 产品标签Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Sun May 24 16:20:49 CST 2020
 */
@RestController
@RequestMapping("/sale/types")
public class SaleTypesController {
    @Autowired
    private SaleTypesService saleTypesService;

    /**
     * 列表产品标签
     */
    @RequestMapping("/list")
    @RequiresPermissions("sale:types:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params), DaoConst.getLIMIT(params));
        List<SaleTypesEntity> saleTypesList = saleTypesService.queryList(params);
        return R.ok(new PageInfo(saleTypesList));
    }

    /**
     * 查看产品标签
     */
    @SysLog("查看产品标签")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sale:types:info")
    public R info(@PathVariable("id") Long id) {
        SaleTypesEntity saleTypes = saleTypesService.get(id);

        return R.ok(saleTypes);
    }

    /**
     * 保存产品标签
     */
    @SysLog("保存产品标签")
    @RequestMapping("/save")
    @RequiresPermissions("sale:types:save")
    public R save(SaleTypesEntity saleTypes) {
        saleTypesService.save(saleTypes);

        return R.ok(saleTypes);
    }

    /**
     * 修改产品标签
     */
    @SysLog("修改产品标签")
    @RequestMapping("/update")
    @RequiresPermissions("sale:types:update")
    public R update(SaleTypesEntity saleTypes) {
        saleTypesService.update(saleTypes);

        return R.ok(saleTypes);
    }

    /**
     * 删除产品标签
     */
    @SysLog("删除产品标签")
    @RequestMapping("/delete")
    @RequiresPermissions("sale:types:delete")
    public R delete(Long[] ids) {
        saleTypesService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有产品标签
     */
    @SysLog("所有产品标签")
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<SaleTypesEntity> saleTypesList = saleTypesService.queryList(params);

        return R.ok(saleTypesList);
    }

    /**
     @ModelAttribute public SearchParam<SaleTypesEntity> searchParam(SearchParam<SaleTypesEntity> params, SaleTypesEntity saleTypes) {
     if (saleTypes != null) {
     params.setEntity(saleTypes);
     }

     return params;
     }
     **/
    /***********自定义开始***********/
}
